//
//  KBoxViewController.swift
//  onemeetingmac
//
//  Created by 张衡 on 2020/7/14.
//  Copyright © 2020 onemeeting. All rights reserved.
//

import Foundation


class KBoxViewController: AsModeViewController {
    
    let KIWidth:CGFloat = 160
    let KIHeight:CGFloat = 200
    let KISapace:CGFloat = 40
    let kData = [
        KBoxData.init(title: "直播", image: NSImage.image(name:"icon_clive"), imageSelect: NSImage.image(name:"icon_clive_select")),
        KBoxData.init(title: "录制", image: NSImage.image(name:"icon_clive"), imageSelect: NSImage.image(name:"icon_clive_select"))
    ]
    var subViews:[KBoxItem] = []
    
    var selectInt:Int = 0
    
    
    override func loadView() {
        let view = NSView.init(frame: NSMakeRect(0, 0, kInvWinWidth, kInvWinHeight))
        view.wantsLayer = true
        view.layer?.backgroundColor = color_dark.cgColor
        self.view = view
    }
    
    override func viewDidLoad() {
        super.viewDidLoad()
        self.setupUI()
        self.loadData()
    }
    
    func loadData() {
        
    }
    
    
    
    func setupUI() {
        
        let kWidth = (KISapace+KIWidth)*CGFloat(self.kData.count)-KISapace
        self.view.addSubview(container)
        container.snp.makeConstraints { (make) in
            make.centerX.equalToSuperview()
            make.top.equalTo(30)
            make.width.equalTo(kWidth)
            make.height.equalTo(KIHeight)
        }
        self.subViews = self.initSubViews(inView: self.container)
        
        self.view.addSubview(startBtn)
        startBtn.snp.makeConstraints { (make) in
            make.width.equalTo(100)
            make.height.equalTo(30)
            make.centerX.equalToSuperview()
            make.bottom.equalTo(-30)
        }
    }
    
    func subViewSelect(index:Int) {
        self.selectInt = index
        for (inx,val) in self.subViews.enumerated() {
            val.isSelected = (inx == index)
        }
    }
    
    lazy var container: NSView = {
        let view = NSView()
        view.wantsLayer = true
        return view
    }()
    
    func initSubViews(inView:NSView) -> [KBoxItem] {
        var subViews:[KBoxItem] = []
        for (inx,val) in self.kData.enumerated() {
            let view = KBoxItem.init(data: val)
            view.tag = inx
            view.tap = { sView in
                self.subViewSelect(index: sView.tag)
            }
            inView.addSubview(view)
            subViews.append(view)
            view.snp.makeConstraints { (make) in
                make.width.equalTo(KIWidth)
                make.height.equalTo(KIHeight)
                make.top.equalToSuperview()
                if inx == 0 {
                    make.left.equalTo(0)
                }else {
                    make.left.equalTo(subViews[inx-1].snp.right).offset(40)
                }
                
            }
        }
        return subViews
    }
    
    lazy var startBtn: LLCustomBtn = {
        let btn = LLCustomBtn()
        btn.wantsLayer = true
        btn.layer?.cornerRadius = 5
        btn.layer?.masksToBounds = true
        btn.defaultTitle = "开启"
        btn.defaultBackgroundColor = color_main108
        btn.defaultTitleColor = color_gray(255)
        btn.defaultFont = NSFont.systemFont(ofSize: 14)
        btn.textAlignment = LLTextAlignmentCenter
        btn.action = #selector(openBtnAction(senber:))
        btn.target = self
        return btn
    }()
    
    
    @objc func openBtnAction(senber:ZHButton) {
        self.view.window?.close()
        //let type = self.selectInt==0 ? OnePushType.live : OnePushType.record
        //TXLiteManager.shared().pushType = type
        TXLiteManager.shared().isLiving = true
        MTNot.postRTMPLive()
    }
}




